<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/layers/mvn_layer.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/layers</a> - mvn_layer.cpp<span style="font-size: 80%;"> (source / <a href="mvn_layer.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">57</td>
            <td class="headerCovTableEntryLo">3.5 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">14</td>
            <td class="headerCovTableEntryLo">14.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;vector&gt;</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : #include &quot;caffe/layers/mvn_layer.hpp&quot;
<span class="lineNum">       4 </span>            : #include &quot;caffe/util/math_functions.hpp&quot;
<span class="lineNum">       5 </span>            : 
<span class="lineNum">       6 </span>            : namespace caffe {
<a name="7"><span class="lineNum">       7 </span>            : </a>
<span class="lineNum">       8 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">       9 </span><span class="lineNoCov">          0 : void MVNLayer&lt;Dtype&gt;::Reshape(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom,</span>
<span class="lineNum">      10 </span>            :       const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top) {
<span class="lineNum">      11 </span><span class="lineNoCov">          0 :   top[0]-&gt;Reshape(bottom[0]-&gt;num(), bottom[0]-&gt;channels(),</span>
<span class="lineNum">      12 </span>            :       bottom[0]-&gt;height(), bottom[0]-&gt;width());
<span class="lineNum">      13 </span><span class="lineNoCov">          0 :   mean_.Reshape(bottom[0]-&gt;num(), bottom[0]-&gt;channels(),</span>
<span class="lineNum">      14 </span>            :       1, 1);
<span class="lineNum">      15 </span><span class="lineNoCov">          0 :   variance_.Reshape(bottom[0]-&gt;num(), bottom[0]-&gt;channels(),</span>
<span class="lineNum">      16 </span>            :       1, 1);
<span class="lineNum">      17 </span><span class="lineNoCov">          0 :   temp_.Reshape(bottom[0]-&gt;num(), bottom[0]-&gt;channels(),</span>
<span class="lineNum">      18 </span>            :       bottom[0]-&gt;height(), bottom[0]-&gt;width());
<span class="lineNum">      19 </span><span class="lineNoCov">          0 :   if ( this-&gt;layer_param_.mvn_param().across_channels() ) {</span>
<span class="lineNum">      20 </span><span class="lineNoCov">          0 :     sum_multiplier_.Reshape(1, bottom[0]-&gt;channels(), bottom[0]-&gt;height(),</span>
<span class="lineNum">      21 </span>            :                             bottom[0]-&gt;width());
<span class="lineNum">      22 </span>            :   } else {
<span class="lineNum">      23 </span><span class="lineNoCov">          0 :     sum_multiplier_.Reshape(1, 1, bottom[0]-&gt;height(), bottom[0]-&gt;width());</span>
<span class="lineNum">      24 </span>            :   }
<span class="lineNum">      25 </span><span class="lineNoCov">          0 :   Dtype* multiplier_data = sum_multiplier_.mutable_cpu_data();</span>
<span class="lineNum">      26 </span><span class="lineNoCov">          0 :   caffe_set(sum_multiplier_.count(), Dtype(1), multiplier_data);</span>
<span class="lineNum">      27 </span><span class="lineNoCov">          0 :   eps_ = this-&gt;layer_param_.mvn_param().eps();</span>
<span class="lineNum">      28 </span><span class="lineNoCov">          0 : }</span>
<a name="29"><span class="lineNum">      29 </span>            : </a>
<span class="lineNum">      30 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      31 </span><span class="lineNoCov">          0 : void MVNLayer&lt;Dtype&gt;::Forward_cpu(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom,</span>
<span class="lineNum">      32 </span>            :     const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top) {
<span class="lineNum">      33 </span><span class="lineNoCov">          0 :   const Dtype* bottom_data = bottom[0]-&gt;cpu_data();</span>
<span class="lineNum">      34 </span><span class="lineNoCov">          0 :   Dtype* top_data = top[0]-&gt;mutable_cpu_data();</span>
<span class="lineNum">      35 </span>            :   int num;
<span class="lineNum">      36 </span><span class="lineNoCov">          0 :   if (this-&gt;layer_param_.mvn_param().across_channels())</span>
<span class="lineNum">      37 </span><span class="lineNoCov">          0 :     num = bottom[0]-&gt;num();</span>
<span class="lineNum">      38 </span>            :   else
<span class="lineNum">      39 </span><span class="lineNoCov">          0 :     num = bottom[0]-&gt;num() * bottom[0]-&gt;channels();</span>
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span><span class="lineNoCov">          0 :   int dim = bottom[0]-&gt;count() / num;</span>
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            :   // subtract mean
<span class="lineNum">      44 </span><span class="lineNoCov">          0 :   caffe_cpu_gemv&lt;Dtype&gt;(CblasNoTrans, num, dim, 1. / dim, bottom_data,</span>
<span class="lineNum">      45 </span>            :       sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());  // EX
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :   caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,</span>
<span class="lineNum">      47 </span>            :       mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">      48 </span>            :       temp_.mutable_cpu_data());
<span class="lineNum">      49 </span><span class="lineNoCov">          0 :   caffe_add(temp_.count(), bottom_data, temp_.cpu_data(), top_data);  // X-EX</span>
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span><span class="lineNoCov">          0 :   if (this-&gt;layer_param_.mvn_param().normalize_variance()) {</span>
<span class="lineNum">      52 </span>            :     // compute variance using var(X) = E((X-EX)^2)
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :     caffe_powx(bottom[0]-&gt;count(), top_data, Dtype(2),</span>
<span class="lineNum">      54 </span>            :         temp_.mutable_cpu_data());  // (X-EX)^2
<span class="lineNum">      55 </span><span class="lineNoCov">          0 :     caffe_cpu_gemv&lt;Dtype&gt;(CblasNoTrans, num, dim, 1. / dim, temp_.cpu_data(),</span>
<span class="lineNum">      56 </span>            :         sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">      57 </span>            :         variance_.mutable_cpu_data());  // E((X-EX)^2)
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span>            :     // normalize variance
<span class="lineNum">      60 </span><span class="lineNoCov">          0 :     caffe_powx(variance_.count(), variance_.cpu_data(), Dtype(0.5),</span>
<span class="lineNum">      61 </span>            :           variance_.mutable_cpu_data());
<span class="lineNum">      62 </span>            : 
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :     caffe_add_scalar(variance_.count(), eps_, variance_.mutable_cpu_data());</span>
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span><span class="lineNoCov">          0 :     caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,</span>
<span class="lineNum">      66 </span>            :           variance_.cpu_data(), sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">      67 </span>            :           temp_.mutable_cpu_data());
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :     caffe_div(temp_.count(), top_data, temp_.cpu_data(), top_data);</span>
<span class="lineNum">      70 </span>            :   }
<span class="lineNum">      71 </span><span class="lineNoCov">          0 : }</span>
<a name="72"><span class="lineNum">      72 </span>            : </a>
<span class="lineNum">      73 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      74 </span><span class="lineNoCov">          0 : void MVNLayer&lt;Dtype&gt;::Backward_cpu(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top,</span>
<span class="lineNum">      75 </span>            :     const vector&lt;bool&gt;&amp; propagate_down,
<span class="lineNum">      76 </span>            :     const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom) {
<span class="lineNum">      77 </span><span class="lineNoCov">          0 :   const Dtype* top_diff = top[0]-&gt;cpu_diff();</span>
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   const Dtype* top_data = top[0]-&gt;cpu_data();</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :   const Dtype* bottom_data = bottom[0]-&gt;cpu_data();</span>
<span class="lineNum">      80 </span><span class="lineNoCov">          0 :   Dtype* bottom_diff = bottom[0]-&gt;mutable_cpu_diff();</span>
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span>            :   int num;
<span class="lineNum">      83 </span><span class="lineNoCov">          0 :   if (this-&gt;layer_param_.mvn_param().across_channels())</span>
<span class="lineNum">      84 </span><span class="lineNoCov">          0 :     num = bottom[0]-&gt;num();</span>
<span class="lineNum">      85 </span>            :   else
<span class="lineNum">      86 </span><span class="lineNoCov">          0 :     num = bottom[0]-&gt;num() * bottom[0]-&gt;channels();</span>
<span class="lineNum">      87 </span>            : 
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :   int dim = bottom[0]-&gt;count() / num;</span>
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :   if (this-&gt;layer_param_.mvn_param().normalize_variance()) {</span>
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :     caffe_mul(temp_.count(), top_data, top_diff, bottom_diff);</span>
<span class="lineNum">      92 </span><span class="lineNoCov">          0 :     caffe_cpu_gemv&lt;Dtype&gt;(CblasNoTrans, num, dim, 1., bottom_diff,</span>
<span class="lineNum">      93 </span>            :           sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());
<span class="lineNum">      94 </span><span class="lineNoCov">          0 :     caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,</span>
<span class="lineNum">      95 </span>            :           mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">      96 </span>            :           bottom_diff);
<span class="lineNum">      97 </span><span class="lineNoCov">          0 :     caffe_mul(temp_.count(), top_data, bottom_diff, bottom_diff);</span>
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span><span class="lineNoCov">          0 :     caffe_cpu_gemv&lt;Dtype&gt;(CblasNoTrans, num, dim, 1., top_diff,</span>
<span class="lineNum">     100 </span>            :             sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());
<span class="lineNum">     101 </span><span class="lineNoCov">          0 :     caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,</span>
<span class="lineNum">     102 </span>            :             mean_.cpu_data(), sum_multiplier_.cpu_data(), 1.,
<span class="lineNum">     103 </span>            :             bottom_diff);
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span><span class="lineNoCov">          0 :     caffe_cpu_axpby(temp_.count(), Dtype(1), top_diff, Dtype(-1. / dim),</span>
<span class="lineNum">     106 </span>            :         bottom_diff);
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span>            :     // put the squares of bottom into temp_
<span class="lineNum">     109 </span><span class="lineNoCov">          0 :     caffe_powx(temp_.count(), bottom_data, Dtype(2),</span>
<span class="lineNum">     110 </span>            :         temp_.mutable_cpu_data());
<span class="lineNum">     111 </span><span class="lineNoCov">          0 :     caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,</span>
<span class="lineNum">     112 </span>            :         variance_.cpu_data(), sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">     113 </span>            :         temp_.mutable_cpu_data());
<span class="lineNum">     114 </span>            : 
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :     caffe_div(temp_.count(), bottom_diff, temp_.cpu_data(), bottom_diff);</span>
<span class="lineNum">     116 </span>            :   } else {
<span class="lineNum">     117 </span><span class="lineNoCov">          0 :     caffe_cpu_gemv&lt;Dtype&gt;(CblasNoTrans, num, dim, 1. / dim, top_diff,</span>
<span class="lineNum">     118 </span>            :       sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());
<span class="lineNum">     119 </span><span class="lineNoCov">          0 :     caffe_cpu_gemm&lt;Dtype&gt;(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,</span>
<span class="lineNum">     120 </span>            :       mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,
<span class="lineNum">     121 </span>            :       temp_.mutable_cpu_data());
<span class="lineNum">     122 </span><span class="lineNoCov">          0 :     caffe_add(temp_.count(), top_diff, temp_.cpu_data(), bottom_diff);</span>
<span class="lineNum">     123 </span>            :   }
<span class="lineNum">     124 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     125 </span>            : 
<a name="126"><span class="lineNum">     126 </span>            : </a>
<span class="lineNum">     127 </span>            : #ifdef CPU_ONLY
<span class="lineNum">     128 </span><span class="lineNoCov">          0 : STUB_GPU(MVNLayer);</span>
<span class="lineNum">     129 </span>            : #endif
<a name="130"><span class="lineNum">     130 </span>            : </a>
<span class="lineNum">     131 </span>            : INSTANTIATE_CLASS(MVNLayer);
<a name="132"><span class="lineNum">     132 </span><span class="lineCov">          3 : REGISTER_LAYER_CLASS(MVN);</span></a>
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
